package com.Util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.Classes.ViewReservation;
import com.Main.faislamovers.*;

public class ViewReservationAdapter extends ArrayAdapter<ViewReservation> {

	public Date date_time;
	Context context;
	int layoutResourceId;
	ArrayList<ViewReservation> listArr;

	public ViewReservationAdapter(Context contexts, int layoutIds,
			ArrayList<ViewReservation> myResLIst) {
		super(contexts, layoutIds, myResLIst);
		this.layoutResourceId = layoutIds;
		this.context = contexts;
		listArr = myResLIst;
	}

	@SuppressLint("SimpleDateFormat")
	public View getView(int position, View convertView, ViewGroup parent) {

		OrderHolder holder = null;
		// get the current order object
		// Order order = getItem(position);

		// listArr.get(position).;

		// inflate the view
		if (convertView == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			convertView = inflater.inflate(R.layout.viewreservationlistview, null);

			holder = new OrderHolder();
			holder.Source = (TextView) convertView
					.findViewById(R.id.Source);
			holder.Destination = (TextView) convertView
					.findViewById(R.id.Destination);
			holder.travel_date = (TextView) convertView
					.findViewById(R.id.travel_date);
			holder.dept_time = (TextView) convertView
					.findViewById(R.id.dept_time);
			holder.arravel_time = (TextView) convertView.findViewById(R.id.arravel_time);
			holder.numb_of_seats = (TextView) convertView
					.findViewById(R.id.numb_of_seats);
			holder.seats_numb = (TextView) convertView
					.findViewById(R.id.seats_numb);
			
			convertView.setTag(holder);
		} else {
			holder = (OrderHolder) convertView.getTag();
		}

		holder.Destination.setText(listArr.get(position).route_to);
		holder.Source.setText(listArr.get(position).route_from);
		
		//holder.travel_date.setText(listArr.get(position).travelDate);
		String trvl_date = listArr.get(position).travelDate.toString().replace("/Date(", "");
		trvl_date = trvl_date.replace(")/", "");
		
		long l3 = Long.parseLong(trvl_date);
		Date date_time_travel = new Date(l3);
		SimpleDateFormat df3 = new SimpleDateFormat("dd-MM-yyy");
		String travel_date_formate = df3.format(date_time_travel);
		
		holder.travel_date.setText(travel_date_formate);
		
		
		
		String date = listArr.get(position).travelDepatureTime.toString()
				.replace("/Date(", "");
		date = date.replace(")/", "");

		long l = Long.parseLong(date);

		Date date_time = new Date(l);
		SimpleDateFormat df2 = new SimpleDateFormat("hh:mm:aa");
		String final_date = df2.format(date_time);

		holder.dept_time.setText(final_date);


		String date2 = listArr.get(position).travelArrivalTime.toString()
				.replace("/Date(", "");
		date2 = date2.replace(")/", "");
		long l2 = Long.parseLong(date2);

		Date date_time_2 = new Date(l2);
		SimpleDateFormat df1 = new SimpleDateFormat("hh:mm:aa");
		String final_date_2 = df1.format(date_time_2);

		holder.arravel_time.setText(final_date_2);
		holder.numb_of_seats.setText(listArr.get(position).res_no_of_seats.toString());
		holder.seats_numb.setText(listArr.get(position).seat_number.toString());
		
		//holder.amount.setText(listArr.get(position).price.toString());

		// Order order = data[position];
		/*
		 * holder.txtDestination.setText(order.route_to);
		 * holder.txtSource.setText(order.route_from);
		 * holder.txtLeaveTime.setText(order.travelDepatureTime);
		 * holder.txtReachTime.setText(order.travelArrivalTime);
		 * holder.txtTime.setText(order.bus_seats);
		 * holder.bus_seater.setText(order.bus_type);
		 * holder.currency.setText(order.Currency);
		 * holder.amount.setText(order.price);
		 */

		return convertView;

	}

	public static class OrderHolder {
		TextView Source;
		TextView Destination;
		TextView travel_date;
		TextView dept_time;
		TextView arravel_time;
		TextView numb_of_seats;
		TextView seats_numb;
		
	}
	
}
